<?php 
	include_once 'classes/DBClass.php';
	include_once 'classes/Product.php';
	include_once 'classes/V_Product.php';

class Campaign {
	
	var $brand_id; 
	var $name;
	var $date_start;
	var $date_finish;
	
		
	// kampanyan�n (markan�n) kategorilerini listeleme
	// array d�nd�r�yor
	function getCategories(){
		$mysql = new DBClass();
		$query = "SELECT category_name FROM `mf_campaign_category` WHERE `brand_id` = '" . $this->brand_id . "'";
		$categories = $mysql->Query($query);
		$categoryList = array();
		$i = 0;
		foreach ($categories as $cat){
			$categoryList[$i] = $cat[0];
			$i++;
		}
		return $categoryList;
	}
	// kategoriye g�re �r�n listeleme yada t�m �r�nler
	// $category == 0 ise hepsini d�nd�r�r
	function getProducts($category){
		$mysql = new DBClass();
		if($category == "all")
			$query = "SELECT * FROM `mf_vw_campaign_products_category` WHERE `brand_id` =  '" . $this->brand_id . "'";
		else
			$query = "SELECT * FROM `mf_vw_campaign_products_category` WHERE `brand_id` = '" . $this->brand_id . "' AND `category_name` = '" . $category ."'" ;
		$products = $mysql->Query($query);
		// product nesne listesi
		$productObjectList = array();
		$i = 0;
		foreach ($products as $prdct) {
			// yeni product nesnesi
			$productObject = new Product();
			// product nesnesi bilgilerini ata
			$productObject->product_id = $prdct[1];
			$productObject->name = $prdct[2];
			$productObject->price = $prdct[3];
			$productObject->image = $prdct[4];
			$productObject->stock = $prdct[5];
			$productObject->short_description = $prdct[6];
			$productObject->properties = $prdct[7];
			// yeni nesneyi listeye ekle
			$productObjectList[$i] = $productObject;
			$i++;
		}
		return $productObjectList;
	}
	
	function displayProducts($catego){
		$ProductDisplayList = $this->getProducts($catego);
		foreach ($ProductDisplayList as $productDisplay) {
			new V_Product($productDisplay);
		}
	}
	// $imageType -> logo , image_detail , image_front 
	function getImage($imageType){
		$mysql = new DBClass();
		$query = "SELECT ". $imageType ." FROM `mf_campaign_image` WHERE `brand_id` = '" . $this->brand_id . "'";
		$imageArray = $mysql->Query($query);
		$image = $imageArray[0];
		return $image[0];
	}
	 
	function setCampaign($brand_id){
		
		$query = "SELECT * FROM `mf_campaign` WHERE `brand_id` = '" . $brand_id . "'";
		$mysql = new DBClass();
		$campaign = $mysql->Query($query);
		$campaignObject = new Campaign();		
		$cmpgn = $campaign[0];		
		$this->brand_id= $cmpgn[1];
		$this->name = $cmpgn[2];
		$this->date_start = $cmpgn[3];
		$this->date_finish = $cmpgn[4];
		
	}
}

?>